import DataSource, { DataSourceMgr } from "../dataSource/dataSource"
import Charts, { IChartConfig, ChartConfigMgr } from "./Charts"

export enum EAxisType {
    Category = 'category',
    Value = "value",
    Time = 'time',
    Log = 'log'
}
export interface IRadarChartOptions {
    title: {
        text: string
    },
    legend: {
        data: Array<string>
    },
    radar: {
        indicator: Array<{ name: string, max: number }>
    },
    series: Array<{
        name: string,
        type: 'radar',
        data: Array<{ value: Array<number>, name: string }>
    }>
}
export interface IRadarChartConfig extends IChartConfig {
    chartOptions: IRadarChartOptions
}
export default class RadarChart extends Charts<IRadarChartConfig>{
    constructor(config: { [key: string]: any }, dataSource: DataSourceMgr, id?: string) {
        super(config, dataSource, id)
    }
    computedConifgStrategy(data: any) {
        let options = <Map<keyof IRadarChartConfig, any>>this.getConfig();
        let radarConfig = options.get("chartOptions");
        const dataLength = options.get("limit") || 0;
        if (dataLength) {
            data = data.slice(0, dataLength);
        }
        try {
            const dataConfFn = new Function("$originData", radarConfig.legend.data);
            const indicatorConfFn = new Function("$originData", radarConfig.radar.indicator);
            const seriesConfFn = new Function("$originData", radarConfig.series[0].data);

            radarConfig.legend.data = dataConfFn(data);
            radarConfig.radar.indicator = indicatorConfFn(data);
            radarConfig.series[0].data = seriesConfFn(data);
            this.setConfig("chartOptions", radarConfig)
        } catch (error) {
            console.error(error)
        }

        // return options;
    }
}